package dreammachine

class DreamsService {
    
    static int emptySize = 0

    def dreamsList(){
        def result = Dream.getAll()
        if (result.size() == emptySize) {
            return new Dream()
        }
        else {
            return result
        }
    }

    def create(name,content){
        def author = "theUser"
        Dream newDream = new Dream()
        newDream.author = author
        newDream.content = content
        newDream.name = name
        if(newDream.validate()){
            newDream.save(flush: true)
            return true
        }else{
            newDream.errors.allErrors.each {
                println it
            }
        }
        
    }
}                                                                                                      
